package book;

public class DirectedWeightGraph {
    // 定义最大路径权值。若顶点间路径权值过大，认为两个顶点没有边连接。
    static final int MAX = 1000000;

    public int[] vertices;          // 顶点集合
    public int[][] edges;           // 邻接矩阵，元素值为边的权重

    public int V;                   // 顶点个数V
    public int E;                   // 边的个数E

    public DirectedWeightGraph(int N) {
        this.V = N;
        this.E = 0;

        // 初始化顶点(0~V-1)
        vertices = new int[V];
        for (int i=0; i < V; i++) {
            vertices[i] = i;
        }
        // 初始化边
        edges = new int[V][V];
        for (int i = 0; i < V; i++) {
            for(int j = 0; j < V; j++) {
                edges[i][j] = MAX;
            }
        }
    }

    // 往图中添加边<u, v>, 权重为weight
    public void addEdge(int u, int v, int weight) {
        edges[u][v] = weight;
        E++;
    }
}